<template>
  <div class="app-container">
    <!--<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="类型" prop="taskType">
        <el-select v-model="queryParams.taskType" placeholder="请选择类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="指派单位" prop="taskDeptCode">
        <el-input
          v-model="queryParams.taskDeptCode"
          placeholder="请输入指派单位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指派时间" prop="assignTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.assignTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择指派时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="截止登记日期" prop="planCompleteTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.planCompleteTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择截止登记日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="taskState">
        <el-input
          v-model="queryParams.taskState"
          placeholder="请输入状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="协同检查人" prop="coinspector">
        <el-input
          v-model="queryParams.coinspector"
          placeholder="请输入协同检查人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检查类型" prop="taskCheckType">
        <el-select v-model="queryParams.taskCheckType" placeholder="请选择检查类型" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否协同" prop="synergistic">
        <el-input
          v-model="queryParams.synergistic"
          placeholder="请输入是否协同"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检查结果" prop="taskResultType">
        <el-select v-model="queryParams.taskResultType" placeholder="请选择检查结果" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="检查时间" prop="checkTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.checkTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择检查时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="检查人" prop="examiner">
        <el-input
          v-model="queryParams.examiner"
          placeholder="请输入检查人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams">
      <el-form-item v-show="cityShow" label="县区" prop="city">
        <el-select
          v-model="queryParams.city"
          clearable
          placeholder="请选择"
          size="small"
          @change="selectCity"
        >
          <el-option
            v-for="item in this.cityData"
            :key="item.deptCode"
            :label="item.deptName"
            :value="item.deptCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-show="townShow" label="乡镇" prop="town">
        <el-select
          v-model="queryParams.town"
          clearable
          placeholder="请选择"
          size="small"
          @change="selectTown"
        >
          <el-option
            v-for="item in this.townData"
            :key="item.deptCode"
            :label="item.deptName"
            :value="item.deptCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-show="villageShow" label="村" prop="village">
        <el-select
          v-model="queryParams.village"
          clearable
          placeholder="请选择"
          size="small"
          @change="selectVillage"
        >
          <el-option
            v-for="item in this.villageData"
            :key="item.deptCode"
            :label="item.deptName"
            :value="item.deptCode">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="检查时间" prop="checkTime">
        <el-date-picker v-model="queryParams.startCheckTime" :picker-options="startDatePicker" clearable
                        placeholder="选择检查时间起"
                        size="small"
                        style="width: 200px"
                        type="date"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
        -
        <el-date-picker v-model="queryParams.endCheckTime" :picker-options="endDatePicker" clearable
                        placeholder="选择检查时间止"
                        size="small"
                        style="width: 200px"
                        type="date"
                        value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="任务状态" prop="taskState">
        <el-select v-model="taskState" clearable placeholder="请选择" size="small">
          <el-option
            v-for="dict in superviseTaskState"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="检查结果" prop="taskResultType">
        <el-select v-model="queryParams.taskResultType" clearable placeholder="请选择" size="small">
          <el-option
            v-for="dict in superviseCheckResult"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="最近记录" prop="taskResultType">
        <el-checkbox v-model="queryParams.showRecentCheckTask" border label=""
                     @change="showRecentCheckTask"></el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="cyan" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <!--<el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['supervise:supervise:add']"
        >新增
        </el-button>
      </el-col>-->
      <!-- <el-col :span="1.5">
         <el-button
           type="success"
           icon="el-icon-edit"
           size="mini"
           :disabled="single"
           @click="handleUpdate"
           v-hasPermi="['supervise:supervise:edit']"
         >修改
         </el-button>
       </el-col>
       <el-col :span="1.5">
         <el-button
           type="danger"
           icon="el-icon-delete"
           size="mini"
           :disabled="multiple"
           @click="handleDelete"
           v-hasPermi="['supervise:supervise:remove']"
         >删除
         </el-button>
       </el-col>-->
      <!--      <el-col :span="1.5">
              <el-button
                type="warning"
                icon="el-icon-download"
                size="mini"
                @click="handleExport"
                v-hasPermi="['supervise:supervise:export']"
              >导出</el-button>
            </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div class="show-icon">注释：若检查时间晚于任务截止时间，则行政区划以 <span
      style="color: red">红色</span> 展示
    </div>
    <div class="show-signal"></div>
    <el-table v-loading="loading" :data="superviseList" @selection-change="handleSelectionChange">
      <el-table-column align="center" type="selection" width="55"/>
      <el-table-column align="center" label="任务编号" prop="taskNo" width="180"/>
      <el-table-column align="center" label="行政区划" min-width="120" prop="taskDeptCode">
        <template slot-scope="scope">
          <span
            v-if="scope.row.planCompleteTime<scope.row.checkTime||(scope.row.planCompleteTime<new Date()&&(scope.row.checkTime==''||scope.row.checkTime==null) )"
            style="color: red;">{{
              scope.row.countyName
            }}-{{ scope.row.townshipName }}-{{ scope.row.superviseDeptName }}</span>
          <span v-else>{{ scope.row.countyName }}-{{ scope.row.townshipName }}-{{ scope.row.superviseDeptName }}</span>
        </template>
      </el-table-column>  
      <el-table-column label="承包方名称" align="center" prop="cbfmc"/>
          <el-table-column label="地块编码" align="center" prop="dkbm"/>
          <el-table-column label="退耕年份" align="center" prop="tyear"/>
          <el-table-column label="面积（亩）" align="center" prop="scmjm"/>
          <el-table-column label="土地性质" align="center" prop="dksx"/>
          <el-table-column label="附着物" align="center" prop="fzwlx"/>
      <el-table-column :formatter="taskTypeFormat" align="center" label="任务类型" prop="taskType"/>
      <el-table-column align="center" label="任务派发时间" prop="assignTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.assignTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :formatter="taskStateFormat" align="center" label="任务状态" prop="taskState"/>
      <el-table-column align="center" label="检查时间" prop="checkTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="任务执行单位" prop="taskDeptName"/>
      <el-table-column align="center" label="检查人" prop="examiner"/>
      <el-table-column :formatter="taskCheckTypeFormat" align="center" label="检查方式" prop="taskCheckType"/>
      <el-table-column align="center" label="协同检查" prop="synergistic">
        <template slot-scope="scope">
          {{ scope.row.synergistic == 'Y' ? '是' : '否' }}
        </template>
      </el-table-column>
      <el-table-column :formatter="taskResultTypeFormat" align="center" label="检查结果" prop="taskResultType"/>
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-view"
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >查看详情
          </el-button>
        </template>
      </el-table-column>
      <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
      />
    </el-table>

    <!--<el-table v-loading="loading" :data="superviseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="taskNo" />
      <el-table-column label="类型" align="center" prop="taskType" />
      <el-table-column label="指派单位" align="center" prop="taskDeptCode" />
      <el-table-column label="指派时间" align="center" prop="assignTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.assignTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="截止登记日期" align="center" prop="planCompleteTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.planCompleteTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="taskState" />
      <el-table-column label="协同检查人" align="center" prop="coinspector" />
      <el-table-column label="检查类型" align="center" prop="taskCheckType" />
      <el-table-column label="是否协同" align="center" prop="synergistic" />
      <el-table-column label="检查结果" align="center" prop="taskResultType" />
      <el-table-column label="检查时间" align="center" prop="checkTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检查人" align="center" prop="examiner" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"退耕人数（人）
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['supervise:supervise:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['supervise:supervise:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>-->

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改监督管理对话框 -->
    <!--<el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-form-item label="任务类型" prop="taskType">
          <el-select v-model="form.taskType" placeholder="请选择" style="width: 100%">
            <el-option
              v-for="dict in superviseTaskType"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="指派的任务单位" prop="taskDeptCode">
          <el-input v-model="form.taskDeptCode" placeholder="请输入指派的任务单位"/>
        </el-form-item>
        <el-form-item label="是否协同检查" prop="synergistic">
          <el-select v-model="form.synergistic" placeholder="请选择" style="width: 10%">
            <el-option
              v-for="dict in synergisticData"
              :key="dict.value"
              :label="dict.name"
              :value="dict.value"
            />
          </el-select>
          <el-input v-model="form.examiner" placeholder="请输入协查单位" style="width: 90%"/>
        </el-form-item>
        <el-form-item label="任务截止登记日期" prop="planCompleteTime">
          <el-date-picker clearable size="small" style="width: 100%"
                          v-model="form.planCompleteTime"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="选择任务截止登记日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检查方式" prop="taskCheckType">
          <el-select v-model="form.taskCheckType" placeholder="请选择" style="width: 100%;">
            <el-option
              v-for="dict in superviseCheckType"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->

    <el-dialog :title="title" :visible.sync="openList" append-to-body width="1300px">
      <div style="min-height: 500px;">
        <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams">
          <el-form-item v-show="cityShow" label="县区" prop="city">
            <el-select
              v-model="queryParams.city"
              clearable
              placeholder="请选择"
              size="small"
              @change="selectCity"
            >
              <el-option
                v-for="item in this.cityData"
                :key="item.deptCode"
                :label="item.deptName"
                :value="item.deptCode">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-show="townShow" label="乡镇" prop="town">
            <el-select
              v-model="queryParams.town"
              clearable
              placeholder="请选择"
              size="small"
              @change="selectTown"
            >
              <el-option
                v-for="item in this.townData"
                :key="item.deptCode"
                :label="item.deptName"
                :value="item.deptCode">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item v-show="villageShow" label="村" prop="village">
            <el-select
              v-model="queryParams.village"
              clearable
              placeholder="请选择"
              size="small"
              @change="selectVillage"
            >
              <el-option
                v-for="item in this.villageData"
                :key="item.deptCode"
                :label="item.deptName"
                :value="item.deptCode">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="任务状态" prop="taskState">
            <el-select v-model="queryParams.taskState" clearable placeholder="请选择" size="small">
              <el-option
                v-for="dict in superviseTaskState"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="检查结果" prop="taskResultType">
            <el-select v-model="queryParams.taskResultType" clearable placeholder="请选择" size="small">
              <el-option
                v-for="dict in superviseCheckResult"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" size="mini" type="cyan" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              :disabled="multiple"
              icon="el-icon-plus"
              size="mini"
              type="primary"
              @click="handleSendTask"
            >任务派发
            </el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <el-table v-loading="loading" :data="superviseList" @selection-change="handleSelectionChange">
          <el-table-column align="center" type="selection" width="55"/>
          <el-table-column align="center" label="行政区划" prop="taskDeptCode"/>
          <el-table-column align="center" label="最近任务派发时间" prop="assignTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.assignTime, '{y}-{m}-{d} {HH} {mm} {ss}') }}</span>
            </template>
          </el-table-column>
          <el-table-column :formatter="taskStateFormat" align="center" label="任务状态" prop="taskState"/>
          <el-table-column align="center" label="最近检查时间" prop="checkTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d} {HH} {mm} {ss}') }}</span>
            </template>
          </el-table-column>
          <el-table-column :formatter="taskResultTypeFormat" align="center" label="检查结果" prop="taskResultType"/>
        </el-table>
      </div>
      <pagination
        v-show="total>0"
        :limit.sync="queryParams.pageSize"
        :page.sync="queryParams.pageNum"
        :total="total"
        @pagination="getList"
      />
    </el-dialog>

    <el-dialog :title="title" :visible.sync="open" append-to-body width="1000px" @close="cancel">
      <el-form ref="form" :model="form" label-width="140px">
        <el-form-item label="任务类型" prop="taskType">
          <el-select v-model="form.taskType" disabled style="width: 100%">
            <el-option
              v-for="dict in superviseTaskType"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="任务接收单位" prop="taskDeptName">
          <el-input v-model="form.taskDeptName" disabled/>
        </el-form-item>
        <el-form-item v-show="isShow" label="协同检查" prop="synergistic">
          <el-select v-model="form.synergistic" disabled style="width: 20%">
            <el-option
              v-for="dict in synergisticData"
              :key="dict.value"
              :label="dict.name"
              :value="dict.value"
            />
          </el-select>
          <el-select v-model="form.coinspector" :disabled="true" :multiple="true"
                     placeholder="请选择"
                     style="width: 80%"
          >
            <el-option
              v-for="item in zzFormData"
              :key="item.deptCode"
              :label="item.deptName"
              :value="item.deptCode"
            />
          </el-select>
          <!--<treeselect
            style="width: 80%;    margin-left: 20%;    margin-top: -37px;"
            v-model="form.coinspector"
            :options="deptOptions"
            :normalizer="normalizer"
            :show-count="true"
            disabled
          />-->
          <!--          :default-expand-level="2"-->

          <!--<el-input v-model="form.coinspector" placeholder="请输入协查单位" style="width: 80%"/>-->
        </el-form-item>
        <el-form-item label="任务截止登记日期" prop="planCompleteTime">
          <el-date-picker v-model="form.planCompleteTime" clearable disabled
                          size="small"
                          style="width: 100%"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检查方式" prop="taskCheckType">
          <el-select v-model="form.taskCheckType" disabled placeholder="请选择" style="width: 100%;">
            <el-option
              v-for="dict in superviseCheckType"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="检查时间" prop="planCompleteTime">
          <el-date-picker v-model="form.checkTime" clearable disabled
                          size="small"
                          style="width: 100%"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检查人" prop="examiner">
          <el-input v-model="form.examiner" disabled/>
        </el-form-item>
        <el-form-item label="检查方式" prop="taskCheckType">
          <el-select v-model="form.taskCheckType" disabled style="width: 100%;">
            <el-option
              v-for="dict in superviseCheckType"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="检查结果" prop="taskResultType">
          <el-select v-model="form.taskResultType" clearable disabled size="small"
                     style="width: 100%">
            <el-option
              v-for="dict in superviseCheckResult"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" disabled type="textarea"/>
        </el-form-item>
        <el-form-item label="附件" prop="fj">
          <!--<el-upload
            :action="productFileAction"
            :before-upload="beforeUpload"
            :file-list="fileList"
            :headers="headers"
            :limit=limit
            :on-exceed="masterFileMax"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :on-success="uploadSuccess"
            accept="image/*"
            class="avatar-uploader"
            disabled
            list-type="picture-card"
            multiple
            name="uploadfiles">
            <i class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>-->
<!--          :on-remove="handleRemove"-->

          <el-upload
            :action="productFileAction"
            :file-list="fileList"
            :before-upload="beforeUpload"
            :headers="headers"
            :on-success="uploadSuccess"
            :on-preview="handlePreview"
            :on-exceed="masterFileMax"
            :limit=limit
            disabled
            multiple
            name="uploadfiles">
            <!--            accept="image/*"-->
            <!--            <i class="el-icon-plus avatar-uploader-icon"></i>-->
            <el-button><i class="el-icon-plus avatar-uploader-icon"></i></el-button>
          </el-upload>
          <el-input v-show="1==2" v-model="form.reportfj" type="textarea"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="cancel">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog :visible.sync="dialogVisible">
      <img :src="dialogImageUrl" alt="" width="100%">
    </el-dialog>
  </div>
</template>

<script>
import {
  addSupervise,
  delSupervise,
  exportSupervise,
  getSupervise,
  listSupervise,
  updateSupervise
} from "@/api/jdgl/supervise";
import {getInfo} from "@/api/login";
import {childlistUse, listDept} from "@/api/system/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getToken} from "@/utils/auth";

export default {
  name: "Supervise",
  components: {Treeselect},
  data() {
    return {
      startDatePicker: this.beginDate(),
      endDatePicker: this.processDate(),
      isShow: false,
      dialogImageUrl: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 菜单树选项
      deptOptions: [],
      deptCode: '',
      // 监督管理表格数据
      superviseList: [],
      superviseTaskType: [],
      superviseCheckResult: [],
      superviseTaskState: [],
      superviseCheckType: [],
      city: '',
      town: '',
      village: '',
      cityShow: '',
      townShow: '',
      villageShow: '',
      cityData: [],
      townData: [],
      villageData: [],
      synergisticData: [{name: '是', value: 'Y'}, {name: '否', value: 'N'}],
      fileList: [],
      limit: 5,
      headers: {Authorization: 'Bearer ' + getToken()},
      productFileAction: process.env.VUE_APP_BASE_API + '/system/resource/profile/upload',
      // 弹出层标题
      title: "",
      dialogVisible: false,
      // 是否显示弹出层
      open: false,
      openList: false,
      taskState: [],
      zzFormData: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskNo: null,
        showRecentCheckTask: null,
        taskType: null,
        taskDeptCode: null,
        assignTime: null,
        planCompleteTime: null,
        taskState: null,
        taskStates: null,
        longitude: null,
        coinspector: null,
        dimension: null,
        taskCheckType: null,
        synergistic: null,
        taskResultType: null,
        reportfj: null,
        checkTime: null,
        startCheckTime: null,
        endCheckTime: null,
        by1: null,
        examiner: null,
        by2: null,
        by3: null,
        by4: null,
        by5: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        taskType: [
          {required: true, message: "任务类型 0本级 1下级不能为空", trigger: "change"}
        ],
        taskState: [
          {required: true, message: "任务状态 0待派发 1待执行 2已执行不能为空", trigger: "blur"}
        ],
        taskCheckType: [
          {required: true, message: "任务检查类型 0实地 1其他不能为空", trigger: "change"}
        ],
      }
    };
  },
  created() {
    this.getDicts('supervise_task_type').then(response => {
      this.superviseTaskType = response.data
    })
    this.getDicts('supervise_check_type').then(response => {
      this.superviseCheckType = response.data
    })
    this.getDicts('supervise_check_result').then(response => {
      this.superviseCheckResult = response.data
    })
    this.getDicts('supervise_task_state').then(response => {
      this.superviseTaskState = response.data
    })

    getInfo().then(response => {
      let deptCode = response.user.dept.deptCode;
      this.deptCode = deptCode;
      this.getList();
      listDept({deptCode: deptCode}).then(response => {
        this.deptOptions = [];
        const dept = {deptId: 0, deptName: '请选择协查单位', children: []};
        dept.children = this.handleTree(response.data, "deptId");
        this.deptOptions.push(dept);
      });

      if (deptCode.length == 4) {//新区
        this.cityShow = true;
        this.townShow = true;
        this.villageShow = true;
        childlistUse(deptCode).then(response => {
          this.cityData = response.data;
        });
      } else if (deptCode.length == 6) {//县
        this.cityShow = false;
        this.townShow = true;
        this.villageShow = true;
        childlistUse(deptCode).then(response => {
          this.townData = response.data;
        });
      } else if (deptCode.length == 9) {//镇
        this.cityShow = false;
        this.townShow = false;
        this.villageShow = true;
        childlistUse(deptCode).then(response => {
          this.villageData = response.data;
        });
      } else if (deptCode.length == 12) {//村
        this.cityShow = false;
        this.townShow = false;
        this.villageShow = false;
      } else {
        this.childlist(1306);
        this.cityShow = true;
        this.townShow = true;
        this.villageShow = true;
      }
    });
  },
  methods: {
    showRecentCheckTask(val) {
      this.getList();
    },
    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.deptId,
        label: node.deptName,
        children: node.children
      };
    },
    handlePreview(file) {
      window.open(file.url);
      /*if (window.navigator.msSaveOrOpenBlob) {
        navigator.msSaveBlob(file.raw, file.name)
      } else {
        let link = document.createElement('a')
        link.download = file.name
        link.href = window.URL.createObjectURL(file.url)
        link.click()
        window.URL.revokeObjectURL(link.href)
      }*/
      /*this.dialogImageUrl = file.url;
      this.dialogVisible = true;*/
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    },
    handleRemove(file, fileList) {
      this.imageTempList = [];
      this.imageList = '';
      if (fileList.length < 1) {
        this.form.reportfj = "";
      }
      fileList.forEach(item => {

        if (item.url.indexOf("blob:") > -1) {
          let url = process.env.VUE_APP_BASE_API + item.response.data[0];
          let imageInfo = {name: file.name, url: url};
          this.imageTempList.push(imageInfo);
          if (this.imageList == "") {
            this.imageList = this.imageList + url;
            this.form.reportfj = this.imageList;
          } else {
            this.imageList = this.imageList + "," + url;
            this.form.reportfj = this.imageList;
          }
        } else {
          let url = item.url;
          let imageInfo = {name: item.name, url: url};
          this.imageTempList.push(imageInfo);
          if (this.imageList == "") {
            this.imageList = this.imageList + url;
            this.form.reportfj = this.imageList;
          } else {
            this.imageList = this.imageList + "," + url;
            this.form.reportfj = this.imageList;
          }
        }
      });
    },
    beforeUpload(file) {
      // 图片显示前做一下判断
      // let isJPG = /^image\/(jpeg|png|jpg)$/.test(file.type);
      let name = file.name.split(".");
      let fileType = name[name.length - 1];
      // 图片显示前做一下判断
      let isJPG = "jpeg|png|jpg".indexOf(fileType) > -1;
      const isLt5M = file.size / 1024 / 1024 < 5;
      if (!isJPG) {
        this.$message.error('上传图片格式不对,只允许上传jpeg、png、jpg格式!');
      }
      if (!isLt5M) {
        this.$message.error('上传头像图片大小不能超过 5MB!');
      }
      return isJPG && isLt5M;
    },
    uploadSuccess(response, file, fileList) {
      this.imageTempList = [];
      this.imageList = '';
      if (response.code == 200) {
        fileList.forEach(item => {
          if (item.url.indexOf("blob:") > -1) {
            if (item.status == "success") {
              let url = process.env.VUE_APP_BASE_API + item.response.data[0];
              let imageInfo = {name: file.name, url: url};
              this.imageTempList.push(imageInfo);
              if (this.imageList == "") {
                this.imageList = this.imageList + url;
                this.form.reportfj = this.imageList;
              } else {
                this.imageList = this.imageList + "," + url;
                this.form.reportfj = this.imageList;
              }
            }
          } else {
            let url = item.url;
            let imageInfo = {name: item.name, url: url};
            this.imageTempList.push(imageInfo);
            if (this.imageList == "") {
              this.imageList = this.imageList + url;
              this.form.reportfj = this.imageList;
            } else {
              this.imageList = this.imageList + "," + url;
              this.form.reportfj = this.imageList;
            }
          }
        });
        // this.timer = setInterval(this.getImageList(fileList), 1000);
      } else {
        this.$message.error(response.msg)
      }
    },
    masterFileMax(files, fileList) {
      this.$message.warning(`最多只允许上传 ${this.limit} 个附件。`);
    },
    getImageList(fileList) {
      if (this.imageTempList.length == fileList.length) {
        this.fileList = this.imageTempList;
        clearInterval(this.timer);
      }
    },
    beginDate() {
      const self = this
      return {
        disabledDate(time) {
          if (self.queryParams.endCheckTime) {  //如果结束时间不为空，则小于结束时间
            return new Date(self.queryParams.endCheckTime).getTime() < time.getTime();
          } else {
          }
        }
      }
    },
    processDate() {
      const self = this
      return {
        disabledDate(time) {
          if (self.queryParams.startCheckTime) {  //如果开始时间不为空，则结束时间大于开始时间
            return new Date(self.queryParams.startCheckTime).getTime() > time.getTime();
          } else {
          }
        }
      }
    },
    // 选择县
    selectCity(val) {
      this.queryParams.cbfbm = val;
      this.queryParams.superviseDeptCode = val;
      if (val != "" && val != null) {
        childlistUse(val).then(response => {
          this.townData = response.data;
        });
      }
    },
    // 选择镇
    selectTown(val) {
      this.queryParams.cbfbm = val
      this.queryParams.superviseDeptCode = val;
      if (val != "" && val != null) {
        childlistUse(val).then(response => {
          this.villageData = response.data;
        });
      }
    },
    // 选择村
    selectVillage(val) {
      this.queryParams.cbfbm = val;
      this.queryParams.superviseDeptCode = val;
    },
    // 字典状态字典翻译
    taskStateFormat(row, column) {
      return this.selectDictLabel(this.superviseTaskState, row.taskState);
    },
    taskResultTypeFormat(row, column) {
      // return row.taskResultType
      
      return this.selectDictLabel(this.superviseCheckResult, row.taskResultType);
    },
    taskCheckTypeFormat(row, column) {
            let arr =  row.taskCheckType.split(',')
      let arrxin = [];
      for(let i = 0 ; i < arr.length; i++){
        for(let o = 0; o < this.superviseCheckType.length ; o++){
          if(arr[i] == this.superviseCheckType[o].dictValue){
            arrxin.push(this.superviseCheckType[o].dictLabel)
          }
        }
      }

      return arrxin.toString();
      // return this.selectDictLabel(this.superviseCheckType, row.taskCheckType);
    },
    taskTypeFormat(row, column) {
      return this.selectDictLabel(this.superviseTaskType, row.taskType);
    },
    /** 查询监督管理列表 */
    getList() {
      this.loading = true;
      let _this = this;
      if (this.taskState == '' || this.taskState == null) {
        this.queryParams.taskStates = '0,1';
      }
      this.queryParams.deptCodeForTaskOrDist = this.deptCode;
      let taskStates = this.taskState;
      this.queryParams.taskStates = taskStates.toString();
      // this.queryParams.superviseDeptCode = this.deptCode;
      listSupervise(this.queryParams).then(response => {
        this.superviseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.fileList = [];
      this.imageList = '';
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        superviseId: null,
        taskNo: null,
        taskType: null,
        taskDeptCode: null,
        assignTime: null,
        planCompleteTime: null,
        taskState: null,
        longitude: null,
        coinspector: null,
        dimension: null,
        taskCheckType: null,
        synergistic: null,
        taskResultType: null,
        reportfj: null,
        checkTime: null,
        by1: null,
        examiner: null,
        by2: null,
        by3: null,
        by4: null,
        by5: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      let startCheckTime = this.queryParams.startCheckTime;
      let endCheckTime = this.queryParams.endCheckTime;
      startCheckTime = startCheckTime == '' || startCheckTime == null ? "" : startCheckTime;
      endCheckTime = endCheckTime == '' || endCheckTime == null ? "" : endCheckTime;
      if ((startCheckTime == '' && endCheckTime != '') || (startCheckTime != '' && endCheckTime == '')) {
        this.$message.warning("请补全检查起止时间");
      } else {
        this.getList();
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.taskState = [];
      this.queryParams.city = '';
      this.queryParams.town = '';
      this.queryParams.village = '';
      this.queryParams.superviseDeptCode = '';
      this.queryParams.startCheckTime = '';
      this.queryParams.endCheckTime = '';
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.superviseId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openList = true;
      // this.open = true;
      this.title = "新增监督任务";
    },
    handleSendTask() {
      this.reset();
      this.open = true;
      // this.open = true;
      this.title = "任务派发";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const superviseId = row.superviseId || this.ids;
      let taskDeptCode = row.taskDeptCode;
      childlistUse(taskDeptCode).then(response => {
        this.zzFormData = response.data;
      });
      getSupervise(superviseId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看详情";
        let htfj = response.data.reportfj;
        if (htfj != "" && htfj != null && htfj != undefined) {
          this.imageList = htfj;
          htfj = response.data.reportfj.split(',');
          htfj.forEach((item, i) => {
            let name = item.split('/')[item.split('/').length - 1];
            let imageInfo = {name: name, url: item};
            this.fileList.push(imageInfo);
          });
        }

        this.form.coinspector = row.coinspector.split(',');

        if (row.taskType == "0") {
          this.isShow = true;
          getInfo().then(response => {
            let deptCode = response.user.dept.deptCode;
            this.deptCode = deptCode;

            if (deptCode.length == 4) {//新区
              this.deptCodeStep = 0;
              let newdeptCode = deptCode.substring(0, 2);
              childlistUse(newdeptCode).then(response => {
                this.cityFormData = response.data;
                this.form.taskDeptCode = deptCode;
              });
            } else if (deptCode.length == 6) {//县
              this.deptCodeStep = 1;
              let newdeptCode = deptCode.substring(0, 4);
              childlistUse(newdeptCode).then(response => {
                this.cityFormData = response.data;
                this.form.taskDeptCode = deptCode;
              });
            } else if (deptCode.length == 9) {//镇
              this.deptCodeStep = 2
              let newdeptCode = deptCode.substring(0, 6);
              childlistUse(newdeptCode).then(response => {
                this.villageFormData = response.data;
              });
            } else if (deptCode.length == 12) {//村
            }
          });
        } else {
          this.isShow = false;
          getInfo().then(response => {
            let deptCode = response.user.dept.deptCode;
            this.deptCode = deptCode;
            if (deptCode.length == 4) {//新区
              this.deptCodeStep = 0;
              childlistUse(deptCode).then(response => {
                this.cityFormData = response.data;
              });
            } else if (deptCode.length == 6) {//县
              this.deptCodeStep = 1;
              childlistUse(deptCode).then(response => {
                this.cityFormData = response.data;
              });
              /* deptCode = deptCode.substring(0, 4);
               childlistUse(deptCode).then(response => {
                 this.cityFormData = response.data;
               });*/
            } else if (deptCode.length == 9) {//镇
              this.deptCodeStep = 3;
              childlistUse(deptCode).then(response => {
                this.villageFormData = response.data;
              });
            } else if (deptCode.length == 12) {//村
            }
          });
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.superviseId != null) {
            updateSupervise(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSupervise(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const superviseIds = row.superviseId || this.ids;
      this.$confirm('是否确认删除监督管理编号为"' + superviseIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delSupervise(superviseIds);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有监督管理数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return exportSupervise(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    }
  }
};
</script>
<style>
.myTitle {
  margin: 10px 0;
  color: #1890FF;
  font-size: 16px;
}

.show-icon {
  text-align: center;
  background-color: #5aaafa;
  color: #fff;
  float: right;
  font-size: 12px;
  margin-right: -8px;
  padding: 8px 5px 8px 5px;
  width: 400px;
}

.show-signal {
  border: 4px solid #939393;
  border-right: 4px solid transparent;
  border-bottom: 4px solid transparent;
  float: right;
  margin-right: -400px;
  margin-top: 29px;
  width: 0;
  height: 0;
}
</style>
